package se.slp.test1;

import android.app.Activity;
import android.app.AlertDialog;

import java.util.List;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

import android.content.Intent;
import android.os.Bundle;

public class History extends Activity{
	private TextView output;
	private DataHelper dh;
	private ListView lv1;
	private String[] lv_arr = { "Burapha", "Computer", "ZONE", "Galaxy", "MSCIM", "Petdo", "Slayer" };
	private String[] data_listview;
	Intent launch_Report;
    
 /** Called when the activity is first created. */

	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		// TODO Auto-generated method stub
				super.onCreate(savedInstanceState);
				setContentView(R.layout.history);
				
				this.output = (TextView) this.findViewById(R.id.his_txtoutput);
				
				this.dh = new DataHelper(this);
				
		        List<String> allData = this.dh.selectAll();
		        StringBuilder sb = new StringBuilder();
		        sb.append("Data in database:\n");
		        //int i = 0;
		        
		       // data_listview = new String[allData.size()];
		        
		      /* for (String name : allData) {
		           sb.append(name + " "); //name = allData
		           i = i+1;
		           if( i%4==0)
		           {
		        	   sb.append("\n");
		           }
		           
		        }*/
		         
		        Log.d("EXAMPLE", "names size - " + allData.size());
		         
		        this.output.setText(sb.toString());
		        
		        /////////////////////////////////////////////////
		        
		       // lv_arr = new String[allData.size()+1];  
		        
		        
		        lv1 = (ListView) findViewById(R.id.ListView01);
		        lv1.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, allData));
		        lv1.setTextFilterEnabled(true);
		        lv1.setOnItemClickListener(new OnItemClickListener() {
		        	
		         public void onItemClick(AdapterView<?> a, View v, int position,long id) {
		        	 /*AlertDialog.Builder adb = new AlertDialog.Builder(History.this);
		        	 adb.setTitle("LVSelectedItemExample");
		        	 adb.setMessage("Selected Item is = "+ lv1.getItemAtPosition(position));
		        	 adb.setPositiveButton("Ok", null);
		        	 adb.show();
		        	 
		        	 */
		        	//String item = (String) getListAdapter().getItem(position);
		        	
		        	launch_Report = new Intent(getApplicationContext(),Report.class);  
		        	launch_Report.putExtra("strInput1", (String) lv1.getItemAtPosition(position));
		        	//String item = (String) lv1.getItemAtPosition(position);
		        	//launch_Report.putExtra("strInput1", (String) lv1.getItemAtPosition(position));
		        	
		  			startActivity(launch_Report);
		         }
		        });
				

	
	}
}
